package com.exe.project.logic;

import java.io.IOException;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.exe.project.data.ReadDataUser;
import com.exe.project.interfaces.IReadDataUser;

/**
 * Servlet implementation class controller
 */
@WebServlet("/controller")
public class controller extends HttpServlet {
	private static final long serialVersionUID = 1L;
	private RequestDispatcher view=null;
	private IReadDataUser rdUser= null;
	
    /**
     * @see HttpServlet#HttpServlet()
     */
    public controller() {
        super();
    }

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		if (request.getParameter("accion").compareToIgnoreCase("Ingresar") == 0 ){
			rdUser = new ReadDataUser(request.getParameter("txtUser").toString(), request.getParameter("txtPass").toString());
			rdUser.setPath(getServletContext().getRealPath( getServletContext().getInitParameter("ConfigFiles")));
			if(rdUser.validateUser()){
				view = request.getRequestDispatcher("viewInsertxml.jsp");
			}else{
				view = request.getRequestDispatcher("Index.jsp");
			}
		}else if(request.getParameter("accion").compareToIgnoreCase("Otro archivo") == 0 ){
			view = request.getRequestDispatcher("viewInsertxml.jsp");
		}else if(request.getParameter("accion").compareToIgnoreCase("Salir") == 0 ){
			view = request.getRequestDispatcher("Index.jsp");
		}
		view.forward(request, response);
	}

}